package com.zhongkai.controller;

import com.zhongkai.app.service.MaintainService;
import com.zhongkai.model.utils.TTHelp;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MaintainController {

    @Autowired
    private MaintainService maintainService;


    /**
     * 添加员工
     *
     * @param tain_name    姓名
     * @param tain_sex     性别
     * @param tain_section 部门
     * @param tain_phone   电话
     * @param tain_mail    邮箱
     * @RequestParam(defaultValue = "0") Integer role
     */
    @RequestMapping(value = "/maintain/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addMaintain(
            String tain_name, String tain_sex, String tain_section, String tain_phone, String tain_mail


    ) {

        String uuid = TTHelp.generate();
        //ZhongkaiResult zhongkaiResult = deviceOperationService.deviceAdd(device_id, device_ip, device_ver, device_code, set_status);
        ZhongkaiResult result = maintainService.addMaintain(uuid, tain_name, tain_sex,
                tain_section, tain_phone, tain_mail);

        return result;
    }


    /**
     * 修改员工信息
     *
     * @param id           员工id
     * @param tain_name    姓名
     * @param tain_sex     性别
     * @param tain_section 部门
     * @param tain_phone   电话
     * @param tain_mail    邮箱
     */
    @RequestMapping(value = "/maintain/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateMaintain(
            @RequestParam(defaultValue = "0") Long id, String tain_name, String tain_sex, String tain_section,
            String tain_phone, String tain_mail


    ) {

        ZhongkaiResult result = maintainService.updateMaintain(id, tain_name, tain_sex,
                tain_section, tain_phone, tain_mail);

        return result;
    }


    /**
     * 删除员工信息
     *
     * @param id 员工id
     */
    @RequestMapping(value = "/maintain/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeMaintain(
            @RequestParam(defaultValue = "0") Long id

    ) {

        ZhongkaiResult result = maintainService.removeMaintain(id);

        return result;
    }


    /**
     * 修改员工状态
     *
     * @param id          员工id
     * @param tain_status 员工状态
     */
    @RequestMapping(value = "/maintain/update2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateMaintain2(
            @RequestParam(defaultValue = "0") Long id, String tain_status

    ) {

        ZhongkaiResult result = maintainService.updateMaintain2(id,tain_status);

        return result;
    }


    /**
     * 员工列表
     */
    @RequestMapping(value = "/maintain/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listMaintain(
            @RequestParam(defaultValue = "0")Integer page, @RequestParam(defaultValue = "0")Integer rows

    ) {

        ZhongkaiResult result = maintainService.listMaintain(page,rows);

        return result;
    }
}
